package com.karaku.karaku_collector.control;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;

import com.karaku.karaku_collector.util.UIUtil;

/**
 * Created by guoping on 2017/11/7.
 */

public class FilterMaskView extends View {

    public static final int SIZE = UIUtil.dp2px(70);

    private Paint mDstPaint, mSrcPaint;

    private float verticalRation, horizontalRatio;

    public FilterMaskView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);

        mDstPaint = new Paint();
        mSrcPaint = new Paint();
        mDstPaint.setAntiAlias(true);
        mSrcPaint.setAntiAlias(true);
        mDstPaint.setColor(Color.RED);
        mSrcPaint.setColor(Color.BLUE);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        Bitmap bmp = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888);
        Canvas c = new Canvas(bmp);

        c.drawColor(0X66000000);

        int offsetX = (getWidth() - SIZE) / 2;
        int offsetY = (getHeight() - SIZE) / 2;
        RectF rect = new RectF(offsetX, offsetY, getWidth() - offsetX, getHeight() - offsetY);

        mSrcPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT));
        c.drawRect(rect, mSrcPaint);

        mDstPaint.setColor(0XFFFFFFFF);
        mDstPaint.setStyle(Paint.Style.STROKE);
        mDstPaint.setStrokeWidth(UIUtil.dp2px(1.5f));
        mDstPaint.setShadowLayer(1, 1, 1, 0X66000000);
        c.drawRect(rect, mDstPaint);

        canvas.drawBitmap(bmp, 0, 0, null);
    }
}
